﻿
@{
    ViewBag.Title = "ArchiveAJInfo";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var Info = ViewBag.Info as List<SGArchiveSystem7xDB.T_ArchiveFields>;
    var Word = ViewBag.Word as List<SGArchiveSystem7xDB.V_ArchiveWord>;
    var Dept = ViewBag.dept as List<SGArchiveSystem7x.Models.CComboboxModel>;
    var ajinfo = ViewBag.AJInfo as System.Data.DataTable;// as List<SGArchiveSystem7xDB.T_ArchiveAj>;
    string[] EditDepartmentID = ViewBag.EditDepartmentID;
    var BJQX = ViewBag.BJQX;
    var WJQX = ViewBag.WJQX;
}

<table class="table table-celled">
    <thead>

    </thead>
    <tbody>
        @{if (ajinfo != null)
            {
                for (int i = 0; i < ajinfo.Rows.Count; i++)
                {
                    foreach (var nn in Info)
                    {
                        if (nn.AF_TYPE == "日期")
                        {
                            string time = "";
                            if (ajinfo.Rows[i][nn.AF_FIELD].ToString() != "" && ajinfo.Rows[i][nn.AF_FIELD].ToString() != "")
                            {
                                time = Convert.ToDateTime(ajinfo.Rows[i][nn.AF_FIELD].ToString()).ToString("yyyy-MM-dd");
                            }
                            <tr>
                                <td><input type="text" class="easyui-datebox" data-options="editable:false" label="@nn.AF_NAME:" labelposition="right" id="ArchiveInit_ArchiveAJInfo_date-@nn.AF_FIELD-@nn.AF_TYPE" style="width:100%;" value="@time" /></td>
                            </tr>
                        }
                        else if (nn.AF_TYPE == "词典")
                        {
                            <tr>
                                <td>
                                    <select id="ArchiveInit_ArchiveAJInfo_cmb-@nn.AF_FIELD" class="easyui-combobox" labelposition="right" label="@nn.AF_NAME" data-options="editable:false" name="ArchiveInit_ArchiveAJInfo_cmb-@nn.AF_FIELD-@nn.AF_TYPE" style="width:100%;" panelHeight="auto">
                                        @{
                                            foreach (var en in Word)
                                            {
                                                if (nn.AF_NAME == en.WT_NAME)
                                                {
                                                    if (ajinfo.Rows[i][nn.AF_FIELD].ToString() == en.WD_ID.ToString())
                                                    {
                                                        <option value="@en.WD_ID" selected="selected">@en.WD_NAME</option>}
                                                    else
                                                    {
                                                        <option value="@en.WD_ID">@en.WD_NAME</option>}
                                                }
                                            }
                                        }
                                    </select>
                                </td>
                            </tr>
                        }
                        else if (nn.AF_TYPE == "部门")
                        {
                            <tr>
                                <td>
                                    <select id="ArchiveInit_ArchiveAJInfo_cmb-@nn.AF_FIELD" class="easyui-combobox" labelposition="right" label="@nn.AF_NAME" data-options="editable:false" name="ArchiveInit_ArchiveAJInfo_cmb-@nn.AF_FIELD-@nn.AF_TYPE" style="width:100%;" panelHeight="auto" disabled="true">
                                        @{
                                            foreach (var en in Dept)
                                            {
                                                if (ajinfo.Rows[i][nn.AF_FIELD].ToString() == en.ID.ToString())
                                                {
                                                    <option value="@en.ID" selected="selected">@en.Text</option>}
                                                else
                                                {
                                                    <option value="@en.ID">@en.Text</option>}
                                            }
                                        }
                                        }
                                    </select>
                                </td>
                            </tr>
                        }
                        else if (nn.AF_TYPE == "唯一")
                        {
                            <tr>
                                <td><input class="easyui-textbox" data-options="required:true" label="@nn.AF_NAME:" labelposition="right" name="ArchiveInit_ArchiveAJInfo_txt+@nn.AF_FIELD" id="ArchiveInit_ArchiveAJInfo_txt-@nn.AF_FIELD-@nn.AF_TYPE" style="width:100%;" value="@ajinfo.Rows[i][nn.AF_FIELD]"></td>
                            </tr>
                        }
                        else
                        {
                            <tr>
                                <td><input class="easyui-textbox"  label="@nn.AF_NAME:" labelposition="right" name="ArchiveInit_ArchiveAJInfo_txt+@nn.AF_FIELD" id="ArchiveInit_ArchiveAJInfo_txt-@nn.AF_FIELD-@nn.AF_TYPE" style="width:100%;" value="@ajinfo.Rows[i][nn.AF_FIELD]"></td>
                            </tr>
                        }
                    }
                    <tr>
                        <td>
                            <select class="easyui-combobox" label="编辑权限" labelposition="right" data-options="editable:false" name="ArchiveInit_ArchiveAJInfo_cmb+bjqx" id="ArchiveInit_ArchiveAJInfo_cmb-bjqx-数字" style="width:100%;" panelHeight="auto">
                                @{
                                    if (BJQX == 0)
                                    {
                                        <option value="0" selected="selected">与部门权限相同</option>
                                        <option value="1">只有本人可以编辑</option>
                                        <option value="2">本人和管理员都可编辑</option>
                                    }
                                    else if (BJQX == 1)
                                    {
                                        <option value="0">与部门权限相同</option>
                                        <option value="1" selected="selected">只有本人可以编辑</option>
                                        <option value="2">本人和管理员都可编辑</option>
                                    }
                                    else
                                    {
                                        <option value="0">与部门权限相同</option>
                                        <option value="1">只有本人可以编辑</option>
                                        <option value="2" selected="selected">本人和管理员都可编辑</option>
                                    }
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <select class="easyui-combobox" label="文件权限" labelposition="right" data-options="editable:false" name="ArchiveInit_ArchiveAJInfo_cmb+wjqx" id="ArchiveInit_ArchiveAJInfo_cmb-wjqx-数字" style="width:100%;" panelHeight="auto">
                                @{
                                    if (WJQX == 0)
                                    {
                                        <option value="0" selected="selected">与部门权限相同</option>
                                        <option value="1">只有本人可以查看</option>
                                        <option value="2">本人和管理员都可查看</option>
                                    }
                                    else if (WJQX == 1)
                                    {
                                        <option value="0">与部门权限相同</option>
                                        <option value="1" selected="selected">只有本人可以查看</option>
                                        <option value="2">本人和管理员都可查看</option>
                                    }
                                    else
                                    {
                                        <option value="0">与部门权限相同</option>
                                        <option value="1">只有本人可以查看</option>
                                        <option value="2" selected="selected">本人和管理员都可查看</option>
                                    }
                                }
                            </select>
                        </td>
                    </tr>
                }
            }
            else
            {
                foreach (var nn in Info)
                {
                    if (nn.AF_TYPE == "日期")
                    {
                        <tr>
                            <td><input type="text" class="easyui-datebox" data-options="editable:false" label="@nn.AF_NAME:" labelposition="right" id="ArchiveInit_ArchiveAJInfo_date-@nn.AF_FIELD-@nn.AF_TYPE" style="width:100%;" value="" /></td>
                        </tr>
                    }
                    else if (nn.AF_TYPE == "词典")
                    {
                        <tr>
                            <td>
                                <select id="ArchiveInit_ArchiveAJInfo_cmb-@nn.AF_FIELD" class="easyui-combobox" labelposition="right" label="@nn.AF_NAME" data-options="editable:false" name="ArchiveInit_ArchiveAJInfo_cmb-@nn.AF_FIELD-@nn.AF_TYPE" style="width:100%;" panelHeight="auto">
                                    @{
                                        foreach (var en in Word)
                                        {
                                            if (nn.AF_NAME == en.WT_NAME)
                                            {
                                                <option value="@en.WD_ID">@en.WD_NAME</option>}
                                        }
                                    }
                                    }
                                </select>
                            </td>
                        </tr>
                    }
                    else if (nn.AF_TYPE == "部门")
                    {
                        <tr>
                            <td>
                                <select id="ArchiveInit_ArchiveAJInfo_cmb-@nn.AF_FIELD" class="easyui-combobox" labelposition="right" label="@nn.AF_NAME" data-options="editable:false" name="ArchiveInit_ArchiveAJInfo_cmb-@nn.AF_FIELD-@nn.AF_TYPE" style="width:100%;" panelHeight="auto">
                                    @{
                                        foreach (var en in Dept)
                                        {
                                            for (int i = 0; i < EditDepartmentID.Length; i++)
                                            {
                                                if (EditDepartmentID[i] == en.ID.ToString())
                                                {
                                                    <option value="@en.ID">@en.Text</option>
                                                }
                                            }
                                        }
                                    }
                                </select>
                            </td>
                        </tr>
                    }
                    else if (nn.AF_TYPE == "唯一")
                    {
                        <tr>
                            <td><input class="easyui-textbox" data-options="required:true" label="@nn.AF_NAME:" labelposition="right" name="ArchiveInit_ArchiveAJInfo_txt+@nn.AF_FIELD" id="ArchiveInit_ArchiveAJInfo_txt-@nn.AF_FIELD-@nn.AF_TYPE" style="width:100%;" value=""></td>
                        </tr>
                    }
                    else
                    {
                        <tr>
                            <td><input class="easyui-textbox" data-options="required:true" label="@nn.AF_NAME:" labelposition="right" name="ArchiveInit_ArchiveAJInfo_txt+@nn.AF_FIELD" id="ArchiveInit_ArchiveAJInfo_txt-@nn.AF_FIELD-@nn.AF_TYPE" style="width:100%;" value=""></td>
                        </tr>
                    }
                }
                <tr>
                    <td>
                        <select class="easyui-combobox" label="编辑权限" labelposition="right" data-options="editable:false" name="ArchiveInit_ArchiveAJInfo_cmb+bjqx" id="ArchiveInit_ArchiveAJInfo_cmb-bjqx-数字" style="width:100%;" panelHeight="auto">
                            <option value="0">与部门权限相同</option>
                            <option value="1">只有本人可以编辑</option>
                            <option value="2">本人和管理员都可编辑</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <select class="easyui-combobox" label="文件权限" labelposition="right" data-options="editable:false" name="ArchiveInit_ArchiveAJInfo_cmb+wjqx" id="ArchiveInit_ArchiveAJInfo_cmb-wjqx-数字" style="width:100%;" panelHeight="auto">
                            <option value="0">与部门权限相同</option>
                            <option value="1">只有本人可以查看</option>
                            <option value="2">本人和管理员都可查看</option>
                        </select>
                    </td>
                </tr>
            }
        }
    </tbody>
    <tfoot>
        <tr>
            <th>
                @{
                    if (ViewBag.ID == null)
                    {
                        <a href="javascipt:void(0);" class="easyui-linkbutton button-blue pull-left" style="width:100px;" onclick="Add()">保存</a> }
                    else
                    {
                        <a href="javascipt:void(0);" class="easyui-linkbutton button-blue pull-left" style="width:100px" onclick="Modify(@ViewBag.ID)">修改</a>}
                }

            </th>
        </tr>
    </tfoot>
</table>
<script>
    var obj =@Html.Raw(Json.Encode(EditDepartmentID));
    $(document).ready(function () {
        //alert(obj.length);
        if (obj.length <= 2)
        {
            $("#ArchiveInit_ArchiveAJInfo_cmb-GDBM").combobox({ disabled: true });
        }
    })
   @* var obj = @Html.Raw(Json.Encode(ajinfo));
    $(document).ready(function () {
        var list = $('input[id^="ArchiveInit_ArchiveAJInfo_txt"]');
       // alert(111);
        for (var i = 0; i < list.length; i++) {
            var str = list[i].id;
            var strs = str.split('-');
            alert(strs[1]);
            for (var name in obj) {
                if (strs[1] == name) {
                    alert(strs[1] + ',' + name);
                   // $('#' + list[i].id).val(obj[name]);
                    $('#' + list[i].id).textbox("setValue", obj[name]);
                    break;
                }
            }
        }

        list = $('input[id^="ArchiveInit_ArchiveAJInfo_date"]');
        for (var i = 0; i < list.length; i++) {
            var str = list[i].id;
            var strs = str.split('-');
            for (var name in obj) {
                if (strs[1] == name) {
                    var dt = formatDate(obj[name]);
                    $('#' + list[i].id).val(dt);
                    //$('#' + list[i].id).datebox("setValue", dt);
                    break;
                }
            }
        }

        list = $('select[id^="ArchiveInit_ArchiveAJInfo_cmb"]');
        for (var i = 0; i < list.length; i++) {
            var str = list[i].id;
            var strs = str.split('-');
            for (var name in obj) {
                if (strs[1] == name) {
                    if (obj[name] != 0 && obj[name] != '0' && obj[name] != '' && obj[name] != null)
                        $('#' + list[i].id).val(obj[name]);
                    //$('#' + list[i].id).combobox("setValue", obj[name]);
                    break;
                }
            }
        }
    });*@
    function Modify(aid)
    {
        var sql1 = "";//字段
        var sql2 = "";//值
        var dh = "";
        var list = $('input[id^="ArchiveInit_ArchiveAJInfo_txt"]');
        for (var i = 0; i < list.length; i++) {
            var str = list[i].id;
            var strs = str.split('-');
            var value = $('#' + list[i].id).val();
            if (strs[2] == "唯一")
                dh = value;
            if (value.length != 4 && strs[2] == '年份') {
                $.messager.alert('提示', '年度类型必须是4位数字!!');
                return false;
            }
            if (isNaN(value) && strs[2] == '数字') {
                $.messager.alert('提示', '页数必须为数字!');
                return false;
            }
            ///如果没有内容，则不添加到SQL语句中
            if (value != '') {
                sql1 = sql1 + strs[1] + " = '" + value + "',";
               // sql2 = sql2+ "'" + value + "',";
            }
        }
        list = $('input[id^="ArchiveInit_ArchiveAJInfo_date"]');
        for (var i = 0; i < list.length; i++) {
            var str = list[i].id;
            var strs = str.split('-');
            var value = $('#' + list[i].id).datebox("getValue");
            if (strs[2] == "唯一")
                dh = value;
            //var date = getNowFormatDate();//当前日期           
            //if (tab(value, date)) {
            //    $.messager.alert('提示', '选择日期小于当前日期!!');
            //    return false;
            //}
            ///如果没有内容，则不添加到SQL语句中
            if (value != '') {
                sql1 = sql1 + strs[1] + " = '" + value + "',";
               // sql2 = sql1 + strs[1] + "=" + value + ",";
            }
        }
        list = $('select[id^="ArchiveInit_ArchiveAJInfo_cmb"]');
        for (var i = 0; i < list.length; i++) {
            var str = list[i].id;
            //alert()
            var strs = str.split('-');
            var value = $('#' + list[i].id).combobox("getValue");
            if (strs[2] == "唯一")
                dh = value;
            ///如果没有内容，则不添加到SQL语句中
            if (value != '') {
                sql1 = sql1 + strs[1] + " = '" + value + "',";
                //sql2 = sql2 + "'" + value + "',";
            }
        }
        $.ajax({
            url: "/ArchiveInit/OpArchiveAJ",
            dataType: "text",
            type: "post",
            data: { sql1: sql1, sql2: sql2, ARID:@ViewBag.ARID, type: "修改", dh: dh, aid: aid },
            success: function (data) {
                if (data == "-1")
                    $.messager.alert('提示！', '修改失败!', 'info');
                else {
                    $.messager.alert('提示！', '修改成功!', 'info');
                    parent.window.ClosewinInfoGrid();
                }
            }
        });
    }
    //function tab(date1, date2) {
    //    var oDate1 = new Date(date1);
    //    var oDate2 = new Date(date2);
    //    if (oDate1.getTime() > oDate2.getTime()) {
    //        return false;//第一大
    //    } else {
    //        return true;//第二大
    //    }
    //}
    ////获取当前日期yyyy-mm-dd
    //function getNowFormatDate() {
    //    var date = new Date();
    //    var seperator1 = "-";
    //    var year = date.getFullYear();
    //    var month = date.getMonth() + 1;
    //    var strDate = date.getDate();
    //    if (month >= 1 && month <= 9) {
    //        month = "0" + month;
    //    }
    //    if (strDate >= 0 && strDate <= 9) {
    //        strDate = "0" + strDate;
    //    }
    //    var currentdate = year + seperator1 + month + seperator1 + strDate;
    //    return currentdate;
    //}
    function Add()
    {
        var sql1 = "";//字段
        var sql2 = "";//值
        var dh = "";
        var list = $('input[id^="ArchiveInit_ArchiveAJInfo_txt"]');
        for (var i = 0; i < list.length; i++) {
            var str = list[i].id;
            var strs = str.split('-');
            var value = $('#' + list[i].id).val();
            if (strs[2] == "唯一")
                dh = value;
            if (value.length != 4 && strs[2]  == '年份') {
                $.messager.alert('提示', '年度类型必须是4位数字!!');
                return false;
            }
            ///如果没有内容，则不添加到SQL语句中
            if (value != '') {
                sql1 = sql1 + strs[1] + ",";
                sql2 = sql2+ "'" + value + "',";
            }
        }
        list = $('input[id^="ArchiveInit_ArchiveAJInfo_date"]');
        for (var i = 0; i < list.length; i++) {
            var str = list[i].id;
            var strs = str.split('-');
            var value = $('#' + list[i].id).datebox("getValue");
            if (strs[2] == "唯一")
                dh = value;
            //var date = getNowFormatDate();//当前日期
            //if (tab(value, date)) {
            //    $.messager.alert('提示', '选择日期小于当前日期!!');
            //    return false;
            //}
            ///如果没有内容，则不添加到SQL语句中
            if (value != '') {
                sql1 = sql1 + strs[1] + ",";
                sql2 = sql2 + "'" + value + "',";
            }
        }
        list = $('select[id^="ArchiveInit_ArchiveAJInfo_cmb"]');
        for (var i = 0; i < list.length; i++) {
            var str = list[i].id;
            var strs = str.split('-');
            var value = $('#' + list[i].id).combobox("getValue");
            if (strs[2] == "唯一")
                dh = value;
            ///如果没有内容，则不添加到SQL语句中
            if (value != '') {
                sql1 = sql1 + strs[1] + ",";
                sql2 = sql2 + "'" + value + "',";
            }
        }
        $.ajax({
            url: "/ArchiveInit/OpArchiveAJ",
            dataType: "text",
            type: "post",
            data: { sql1: sql1, sql2: sql2, ARID:@ViewBag.ARID, type: "著录", dh: dh },
            success: function (data) {
                if (data == "0")
                    $.messager.alert('提示！', '档案重复,添加失败!', 'info');
                else {
                    $.messager.alert('提示！', '添加成功!', 'info');
                    parent.window.ClosewinInfoGrid();
                }
            }
        });
    }
</script>

